﻿using System.IO;
using BitTorrent.File;
using MbUnit.Framework;

namespace UnitTests.TorrentFile
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestFixture]
    public class UnitTest1
    {
        [Test]
        public void OpenTorrentFileAndReSaveIt() {
            foreach (string path in Directory.GetFiles(@"c:\Temp\torrentFiles\")) {
                MetaFile metaFile = new MetaFile(path);

                Crc32 crc32 = new Crc32();
                using (FileStream f = System.IO.File.Open(path, FileMode.Open)) crc32.ComputeHash(f);
                uint crc1 = crc32.CrcValue;

                metaFile.Save(path + ".save");

                using (FileStream f = System.IO.File.Open(path + ".save", FileMode.Open)) crc32.ComputeHash(f);
                uint crc2 = crc32.CrcValue;

                Assert.AreEqual(crc1, crc2, string.Format("Path: {0}", path));
            }
        }
    }
}
